package framework.http.bean;

import java.io.File;

import framework.http.Http;


public class HttpTask {
	private String url;
	private int taskType;
	private int method;
	private HttpParam param;
	private int responseCode;
	private String data;
	private HttpHeader httpHeader;
	private HttpCookie httpCookie;

	public void addParam(String key, String value) {
		param.add(key, value);
	}

	public void addParam(String key, int value) {
		param.add(key, value);
	}

	public void addParam(String key, long value) {
		param.add(key, value);
	}

	public void addParam(String key, boolean value) {
		param.add(key, value);
	}

	public void addParam(String key, double value) {
		param.add(key, value);
	}

	public void addParam(String key, char value) {
		param.add(key, value);
	}

	public void addParam(String key, float value) {
		param.add(key, value);
	}

	public void addParam(String key, File value) {
		param.add(key, value);
	}

	public void addHeader(String key, String value) {
		if (this.httpHeader == null) {
			this.httpHeader = new HttpHeader();
		}
		this.httpHeader.add(key, value);
	}

	public void addCookie(String key, String value) {
		if (this.httpCookie == null) {
			this.httpCookie = new HttpCookie();
		}
		this.httpCookie.add(key, value);
	}

	public boolean isMultipart() {
		return param.isMultipart();
	}

	public String paramForGet() {
		if (method == Http.GET) {
			return param == null ? "" : ("?" + param.paramForGet());
		} else {
			throw new RuntimeException("不是get方法");
		}
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getMethod() {
		return method;
	}

	public void setMethod(int method) {
		this.method = method;
	}

	public HttpParam getParam() {
		return param;
	}

	public void setParam(HttpParam param) {
		this.param = param;
	}

	public int getResponseCode() {
		return responseCode;
	}

	public void setResponseCode(int responseCode) {
		this.responseCode = responseCode;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public HttpHeader getHttpHeader() {
		return httpHeader;
	}

	public void setHttpHeader(HttpHeader header) {
		this.httpHeader = header;
	}

	public boolean hasHttpHeader() {
		return this.httpHeader != null && this.httpHeader.size() > 0;
	}

	public HttpCookie getHttpCookie() {
		return httpCookie;
	}

	public void setHttpCookie(HttpCookie cookie) {
		this.httpCookie = cookie;
	}

	public boolean hasHttpCookie() {
		return this.httpCookie != null && this.httpCookie.size() > 0;
	}

	public int getTaskType() {
		return taskType;
	}

	public void setTaskType(int taskType) {
		this.taskType = taskType;
	}

}
